package C046;

import java.util.Arrays;

/**
 * ClassName: C07
 * Package: C046
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/8 18:19
 * @Version 1.0
 * @Since 1.0
 */
public class C07 {
    public static void main(String[] args) {
        System.out.println(findTheLongestSubstring("leetcodeisgreat"));
    }

    public static int findTheLongestSubstring(String s) {
        char[] charArray = s.toCharArray();
        int[] map = new int[32];
        Arrays.fill(map, -2);
        map[0] = -1;
        int status = 0;
        int index = 0;
        int res = 0;
        for (int i = 0; i < charArray.length; i++) {
            index = getIndex(charArray[i]);
            if(index != -1) {
                status ^= (1 << index);
            }
            if(map[status] != -2) {
                res = Math.max(res, i - map[status]);
            }else {
                map[status] = i;
            }
        }
        return res;
    }

    private static int getIndex(char c) {
        if(c == 'a') {
            return 0;
        }else if(c == 'e') {
            return 1;
        } else if(c == 'i') {
            return 2;
        } else if(c == 'o') {
            return 3;
        } else if(c == 'u') {
            return 4;
        }
        return -1;
    }
}
